package com.hx.springboot1.dao;

import com.hx.springboot1.pojo.dto.ChooseDTO;
import com.hx.springboot1.pojo.dto.ScoreModelDTO;
import com.hx.springboot1.pojo.entity.TabChoose;
import com.hx.springboot1.pojo.entity.TabYear;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Author: hx
 * Date: 2021-05-14 15/53
 * Description: Nothing else
 */
@Repository
@Mapper
public interface ChooseDao {
    @Select("select * from tab_choose where stu_id=#{stuId}")
    TabChoose chooseByStuId(int stuId);
    @Select("select a.course_id,course_name,a.stu_id,stu_name from tab_choose a\n" +
            " join tab_course b on a.course_id = b.course_id\n" +
            " join tab_student c on a.stu_id = c.stu_id\n" +
            " where a.stu_id = #{stuId} and a.course_id not in (select course_id from tab_score where stu_id = #{stuId})")
    List<ScoreModelDTO> selectStuAndCourseByStuId(int stuId);
    @Delete("delete from tab_choose where stu_id = #{sId}")
    int delChooseByStuId(int sId);
    @Delete("delete from tab_choose where course_id = #{courseId}")
    int delTeachByCourseId(int courseId);
    @Select("select choose_id,a.stu_id,a.course_id,b.course_name,a.year_id,c.year_name,a.choose_term from tab_choose a\n" +
            "join tab_course b on a.course_id=b.course_id\n" +
            "join tab_year c on a.year_id = c.year_id\n" +
            "where stu_id = #{stuId}\n" +
            "ORDER BY a.stu_id")
    List<ChooseDTO> getChooseByStuId(int stuId);
    @Select("select * from tab_year")
    List<TabYear> getYear();
    @Select("select * from tab_choose where stu_id = #{stuId} and course_id = #{courseId} and year_id = #{yearId}")
    List<TabChoose> checkChoose(int stuId,int courseId,int yearId);
    @Insert("insert into tab_choose(stu_id,course_id,year_id,choose_term)" +
            " values(#{stuId},#{courseId},#{yearId},#{chooseTerm})")
    int insertChoose(int stuId,int courseId,int yearId,int chooseTerm);
    @Delete("delete from tab_choose where choose_id = #{chooseId}")
    int delChoose(int chooseId);
    @Select("select * from tab_choose where choose_id = #{chooseId}")
    TabChoose selectByChooseId(int chooseId);
}
